# Replication for study 3 in The Supreme Court as an Electoral Issue: Evidence from Three Studies 
# Authors: Alex Badas (abadas@uh.edu) and Beth Simas (ensimas@uh.edu)
# Journal: Political Science Research and Methods 


require(cregg)
require(foreign)
require(ggplot2)


# Load data for Republican particpants 
Study3Republicans<-read.dta("Study3Reps.dta")

#Republican Candidate Selected. Replicates Figure 8
Figure8 <- candidate_selected~Issue
plot(mm(Study3Republicans, Figure8, id = ~ID), vline = .5)+
  ggtitle("Republican Candidate Selected")+
  theme(legend.position="none")

# Republican Candidate Selection. Full analysis. Replicates Figure 7 in appendix
 Figure7appen<- candidate_selected~ Issue + Age +Gender+Race+Education+Experience+Media+Chances+Family+Military
plot(mm(Study3Republicans, Figure7appen, id = ~ID), vline = .5,position_dodge=(width=1.75))+
  ggtitle("Republican Participants: Candidate Selected")+
  theme(legend.position="none")


##Republican Candidate Rating Replicates Figure 9 in appendix. 
Figure9appen <- candidate_rating~ Issue + Age +Gender+Race+Education+Experience+Media+Chances+Family+Military
plot(mm(Study3Republicans, Figure9appen, id = ~ID), vline = 56.241)+
  ggtitle("Republican Candidate Rating")+
  theme(legend.position="none")

#Candidate Rating Issues only
Figure9bappend <- candidate_rating~Issue
plot(mm(Study3Republicans, Figure9bappend, id = ~ID), vline = 56.241)+
  ggtitle("Republican Candidate Rating")+
  theme(legend.position="none")


# Load the data for Democrat participants 
Study3Democrats<-read.dta("Study3Dems.dta")
#Candidate Selection. Replicates Figure 9
Figure9 <- candidate_selected~Issue
# Generates Figure 9 
plot(mm(Study3Democrats, Figure9, id = ~ID), vline = .5)+
  ggtitle("Democrat Participants: Candidate Selected")+
  theme(legend.position="none")
#Democratic Candidate Selected Full Analysis. Repliacates appendix Figure 8
Figure8append <- candidate_selected~ Issue + Age +Gender+Race+Education+Experience+Media+Chances+Family+Military
plot(mm(Study3Democrats, Figure8append, id = ~ID), vline = .5)+
  ggtitle("Democrat Participants: Candidate Selected")+
 theme(legend.position="none")




#Democratic Candidate Rating analysis. Repliacates appendix Figure 10
Figure10append <- candidate_rating~ Issue + Age +Gender+Race+Education+Experience+Media+Chances+Family+Military
plot(mm(Study3Democrats, Figure10append, id = ~ID), vline = 55.99)+
  ggtitle("Democrat Candidate Rating")+
  theme(legend.position="none")
#Candidate Rating Issues only. Replicates appendix Figure 10
Figure10bappend <- candidate_rating~Issue
plot(mm(Study3Democrats, Figure10bappend, id = ~ID), vline = 55.99)+
  ggtitle("Democrat Candidate Rating")+
  theme(legend.position="none")






